<template>
    <Form
            :form-items="formItems"
            :init-data-url="$baseURL.crm + '/crm/customer/' + $route.params.id"
            :handle-init-data="(data)=>{
                data.companyId__label = data.companyName
                data.departmentId__label = data.departmentName
                return data
            }"
    ></Form>
</template>

<script>
    import Form from '../../../../common-util/src/components/page/Form.vue'
    export default {
        components:{
            Form
        },
        data(){
            return {
                formItems:[
                    {
                        field: {
                            name: 'code'
                        },
                        element:{
                            label: '客户编号',
                            disabled: true
                        }
                    },
                    {
                        field: {
                            name: 'appellation'
                        },
                        element:{
                            label: ' 称呼',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'name'
                        },
                        element:{
                            label: '真实姓名'
                        }
                    },
                    {
                        field: {
                            name: 'genderDictId'
                        },
                        element:{
                            label: '性别',
                            type: 'selectDict',
                            selectDict: {
                                groupCode: 'gender'
                            }
                        }
                    },
                    {
                        field: {
                            name: 'age'
                        },
                        element:{
                            label: '年龄'
                        }
                    },
                    {
                        field: {
                            name: 'birthDay'
                        },
                        element:{
                            label: '生日',
                            type: 'date',
                            date: {
                                type: 'date'
                            }
                        }
                    },
                    {
                        field: {
                            name: 'companyId',
                            companyId__label: ''
                        },
                        element:{
                            label: '客户所在公司',
                            type: 'inputSelectTree',
                            inputSelectTree:{
                                dataUrl: this.$baseURL.crm +  '/crm/company/tree'
                            },
                        }
                    },
                    {
                        field: {
                            name: 'departmentId',
                            departmentId__label: ''
                        },
                        element:{
                            label: '客户所在部门',
                            type: 'inputSelectTree',
                            inputSelectTree:{
                                dataUrl: (form)=>{
                                    if(!form.companyId){
                                        return ''
                                    }
                                    return this.$baseURL.crm +  '/crm/department/tree?companyId=' +  form.companyId
                                }
                            },
                            disabled: (form)=> {
                                return !form.companyId
                            }
                        }
                    },
                    {
                        field: {
                            name: 'categoryDictId'
                        },
                        element: {
                            label: '客户来源',
                            type: 'selectDict',
                            selectDict: {
                                groupCode: 'customer_category'
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'version'
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'put',
                                    url: this.$baseURL.crm + '/crm/customer/' +this.$route.params.id,
                                    label: '保存'
                                },
                                {
                                    action: 'reset',
                                    label: '重置',
                                    type: 'default'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        mounted(){
        },
        methods:{
        }
    }
</script>

<style scoped>

</style>